{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">广告列表</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm layui-btn-primary" href="{:url('ads/Adsposition/index')}">返回广告位</a>
      <a class="layui-btn layui-btn-sm layui-btn-danger confirm layui-batch-all" data-href='{:url("delete")}'>批量删除</a>
      <a class="layui-btn layui-btn-sm" href="{:url('ads/ads/add',['poist_id'=>$poist_id])}">添加广告</a>

    </div>
</script>
<script type="text/html" id="type">
    {{# if(d.linktype ==0){ }}
  文字链接
  {{#  } else { }}
  图片链接
  {{#  } }}
</script>
<script type="text/html" id="image">
    {{# if(d.image ==0){ }}
  无
  {{#  } else { }}
  有
  {{#  } }}

</script>
<script type="text/html" id="barTool">

    <a href='{:url("edit")}?id={{ d.ad_id }}' class="layui-btn layui-btn-xs">编辑</a>
    <a href='{:url("delete")}?ids={{ d.ad_id }}' class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
</script>
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="is_show" value="{{d.ad_id}}" data-href="{:url('setstate')}?id={{d.ad_id}}" lay-skin="switch" lay-text="禁用|开启" lay-filter="switchStatus" {{d.is_show==1?'checked':'' }}>
</script>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/admin/js/common.js"></script>
<script>
layui.use('table', function() {
    var table = layui.table,
        $ = layui.$,
        form = layui.form;
    table.render({
        elem: '#dataTable',
        toolbar: '#toolbarDemo',
        url: '{:url("ads/ads/index",["poist_id"=>$poist_id])}',
        cols: [
            [
                { type: 'checkbox', fixed: 'left' },
                { field: 'listorder', width: 70, title: '排序', edit: 'text' },
                { field: 'ad_id', width: 100, title: '广告ID' },
                { field: 'title', title: '广告名称' },
                { field: 'name', title: '广告英文名称' },
                { field: 'bg_color', title: '背景颜色' },
                { field: 'thumb', title: 'pc图片' },
                { field: 'm_thumb', title: '手机图片' },
                { field: 'url', title: '广告url' },
                { field: 'cat_id', title: '栏目id' },
                { field: 'is_show', width: 100, align: "center", title: '是否显示', templet: '#statusTpl', unresize: true },
                { field: 'start_time', width: 100, title: '开始时间' },
                { field: 'end_time', width: 100, title: '结束时间' },
                { field: 'description', width: 100, title: '描述' },

                { fixed: 'right', width: 150, title: '操作', toolbar: '#barTool' }
            ]
        ],
        page: {}
    });

    //监听单元格编辑
    table.on('edit(dataTable)', function(obj) {
        var value = obj.value,
            data = obj.data;
        $.post('{:url("ads/ads/listorder")}', { 'id': data.ad_id, 'value': value }, function(data) {
            if (data.code == 1) {
                layer.msg(data.msg,{},function () {
                    window.location.reload()
                });
            } else {
                layer.msg(data.msg,{},function () {
                    window.location.reload()
                });
            }

        })
    });
});
function see_img(url) {
    layer.open({
        type: 1,
        area: ['70%', '60%'], //宽高
        content: '<img src="'+url+'" alt="" style="max-width: 100%">'
    });
}
</script>
{/block}
